import http, {getRequest} from "../../../utils/http";
import {Api} from "../../../utils/api";
import Dialog from "@vant/weapp/dialog/dialog";

Page({
    data: {
        productInfo: {
            id: 0,
        },
        materialList: []
    },
    onLoad: function (options) {
        const id = options.id
        this.setData({'productInfo.id': id})
        this.getLinkMaterial()
    },
    getLinkMaterial() {
        const id = this.data.productInfo.id;
        http.getRequest(Api.getProductLinkInfo, {id}, (res) => {
            const productInfo = {
                id: res.data.id,
                name: res.data.name,
                image: res.data.image,
            }
            const materialList = res.data.linkList
            this.setData({productInfo, materialList})
        })
    },
    confirmLink(e) {
        const id = this.data.productInfo.id
        const links = e.detail
        http.postRequest(Api.saveProductLink, {id, links}, (res) => {
            Dialog.alert({title: '提示', message: '保存成功'}).then(() => {
                wx.navigateBack()
            })
        })
    }
});
